package logic

import (
	"baidu/baidurpc/baidurpc"
	"baidu/baidurpc/internal/svc"
	"baidu/models/mysql"
	"context"
	"fmt"

	"github.com/zeromicro/go-zero/core/logx"
)

type ForumClassAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewForumClassAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ForumClassAddLogic {
	return &ForumClassAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 分类添加
func (l *ForumClassAddLogic) ForumClassAdd(in *baidurpc.ForumClassAddRequest) (*baidurpc.ForumClassAddResponse, error) {
	// todo: add your logic here and delete this line

	class := mysql.ForumClass{
		ClassName: in.ClassName,
		UserId:    in.UserId,
		PostId:    in.Post,
	}

	if class.UserId != in.UserId {
		return nil, fmt.Errorf("不属于体育分类下的")
	}

	mysql.DB.Debug().Create(&class)

	return &baidurpc.ForumClassAddResponse{
		UserId: int64(class.ID),
	}, nil
}
